package Java网络编程.TCP通信程序练习.p1_服务器给出反馈;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/*服务器端：接收数据，给出反馈*/
public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10);

        Socket s = ss.accept();

        //服务器接收客户发来的信息
        InputStream is = s.getInputStream();
        byte[] bys = new byte[1024];
        int len = is.read(bys);
        String data = new String(bys,0,len);
        System.out.println("客户端发来信息：\n"+data);

        //服务器做出反馈
        OutputStream os = s.getOutputStream();
        os.write("数据已收到，007收到请回答".getBytes());

        ss.close();
    }
}
